n,list1,mark = int(input()),input().split(),input()
print(list1,type(list1))
for i in range(n):
    list1[i] = int(list1[i])
if mark == "0":
    list1.sort()
elif mark == "1":
    list1.sort(reverse=True)
for i in range(len(list1)):
    print(list1[i], end=" ")
